package telco.provider;

import java.util.Collection;

import swa2012.telco.broker.BrokerCallback;
import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Message;
import swa2012.telco.broker.beans.ReceiveMessageStatus;

public class BrokerCallbackImpl implements BrokerCallback {

	private final MessageStorage messageStorage;
	private final TelcoProvider telcoProvider;
	
	public BrokerCallbackImpl(MessageStorage messageStorage,TelcoProvider telcoProvider) {
		this.messageStorage = messageStorage;
		this.telcoProvider = telcoProvider;
	}

	public Collection<Client> listClients() {
		return telcoProvider.getProviderClients();
	}

	public boolean ping() {
		return true;
	}
	
	public ReceiveMessageStatus receiveMessage(Message msg) {
		if(msg.getReceiver()==null)
			return ReceiveMessageStatus.RECEIVE_MESSAGE_ERROR;
		
		messageStorage.addMessage(msg);
		return ReceiveMessageStatus.RECEIVE_MESSAGE_OK;
	}

}
